package com.ruoyi.web.controller.charge;

import com.ruoyi.charge.service.SelectService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("charge/select")
public class SelectController extends BaseController {
    @Autowired
    private SelectService selectService;

    @PreAuthorize("@ss.hasPermi('charge:select:get')")
    @PostMapping("/{registerNumber}")
    public TableDataInfo getOrders(@PathVariable String registerNumber) {
        System.out.println("registerNumber = " + registerNumber);
        return getDataTable(selectService.getChargeOrderList(registerNumber, ""));
    }

    @PreAuthorize("@ss.hasPermi('charge:select:get')")
    @GetMapping("/{patientName}")
    public TableDataInfo getOrders1(@PathVariable String patientName) {
        System.out.println("patientName = " + patientName);
        return getDataTable(selectService.getChargeOrderList("", patientName));
    }


    //    获取挂号单ID
    @PreAuthorize("@ss.hasPermi('charge:select:get')")
    @PostMapping("/registerCode/{registerNumber}")
    public String getRegisterCode1(@PathVariable String registerNumber) {
        System.out.println("registerNumber = " + registerNumber);
        return selectService.getRegisterNumber(registerNumber, "");
    }

    @PreAuthorize("@ss.hasPermi('charge:select:get')")
    @GetMapping("/registerCode/{patientName}")
    public String getRegisterCode(@PathVariable String patientName) {
        System.out.println("patientName = " + patientName);
        return selectService.getRegisterNumber("", patientName);
    }


    @PreAuthorize("@ss.hasPermi('charge:order:edit')")
    @Log(title = "处方订单", businessType = BusinessType.UPDATE)
    @GetMapping("/update/{orderNumber}")
    public AjaxResult edit(@PathVariable String orderNumber) {
        return toAjax(selectService.updateOrder(orderNumber));
    }

}
